home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / rayshade / graphtal.lzh / Graphtal.Amiga / AMIGA_Window.C next >
C/C++ Source or Header  |  1980-02-02  |  3KB  |  174 lines

  1. /*
  2.  * AMIGA_Window.C - AMIGA window driver.
  3.  *
  4.  * Copyright (C) 1992, Lucas Ammon
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #include <stdlib.h>
  20.  
  21. #include "AMIGA_Window.h"
  22. #include "Error.h"
  23.  
  24. extern "C" printf(...);
  25. //___________________________________________________________ AMIGA_Window
  26.  
  27.  
  28. AMIGA_Window::AMIGA_Window() {}
  29.  
  30.  
  31. void AMIGA_Window::open(int width, int height, const rcString& windowName)
  32. {
  33.  
  34.   struct NewWindow nw = 
  35.   { 
  36.     0,10,
  37.     400,400,
  38.     3,
  39.     1,
  40.     VANILLAKEY,
  41.     WINDOWDEPTH|WINDOWDRAG|SMART_REFRESH|GIMMEZEROZERO,
  42.     NULL,
  43.     NULL,
  44.     NULL,
  45.     NULL,
  46.     NULL,
  47.     20,
  48.     20,
  49.     640,
  50.     512,
  51.     WBENCHSCREEN             
  52.   };
  53.  
  54.   printf("Window name: %s ...\n",windowName.chars());
  55.  
  56.   BaseWindow::open(width, height, windowName);
  57.  
  58.   WindowName=windowName;
  59.   w_xres=width;
  60.   w_yres=height;
  61.  
  62.   nw.Title=(unsigned char *)WindowName.chars();
  63.   nw.Width=width;
  64.   nw.Height=height;
  65.  
  66.  
  67.   if(!(GfxBase = gfxbase = (struct GfxBase *)OpenLibrary("graphics.library",0))) {
  68.     Error(ERR_PANIC,rcString("can't open graphics library"));
  69.   }
  70.  
  71.   if(!(IntuitionBase = intuitionbase = (struct IntuitionBase *)OpenLibrary("intuition.library",0))){
  72.      CloseLibrary(gfxbase);
  73.      Error(ERR_PANIC,rcString("can't open intuition library"));
  74.   }
  75.  
  76.  
  77.   if (!(w = (struct Window *)OpenWindow(&nw) )) {
  78.      CloseLibrary(gfxbase);
  79.      CloseLibrary(intuitionbase);
  80.      Error(ERR_PANIC,rcString("can't open window"));
  81.   }
  82.  
  83.   rp = w->RPort;
  84.  
  85.   SetAPen(rp,1);
  86.   SetBPen(rp,0);
  87.  
  88. }
  89.  
  90. void AMIGA_Window::close()
  91. {
  92.  
  93.   printf("Window close ...\n");
  94.  
  95.   BaseWindow::close();
  96.  
  97.   CloseWindow(w);              
  98.   CloseLibrary(gfxbase);
  99.   CloseLibrary(intuitionbase);
  100.  
  101. }
  102.  
  103. void AMIGA_Window::clear()
  104. {
  105.   printf("Window clear ...\n");
  106.  
  107.   BaseWindow::clear();
  108.  
  109.   SetRast(rp,0);
  110.  
  111. }
  112.  
  113. char AMIGA_Window::waitForKey()
  114. {
  115.  
  116.   ULONG MessageClass;
  117.   USHORT code;
  118.   LONG warte;
  119.  
  120.   printf("Window wait for key ...\n");
  121.  
  122.   for(;;) {
  123.     if (message = (struct IntuiMessage *)GetMsg(w->UserPort)) {                
  124.       MessageClass = message->Class; 
  125.       code = message->Code;
  126.       ReplyMsg(message);
  127.       if (MessageClass == VANILLAKEY) {
  128.         return(code);  
  129.       }
  130.     }           
  131.   }
  132.  
  133. }
  134.  
  135. void AMIGA_Window::writeText(const rcString& msg, int x, int y)
  136. {
  137.  
  138.   struct IntuiText txt =
  139.   {
  140.     1,0,
  141.     JAM1,
  142.     0,0,
  143.     NULL,
  144.     NULL,
  145.     NULL
  146.   };
  147.  
  148.   printf("Window text: %s x: %d y: %d ...\n",msg.chars(),x,y);
  149.  
  150.   txt.IText=(unsigned char *)msg.chars();
  151.   PrintIText(rp,&txt,x,w_yres-y);
  152.  
  153. }
  154.  
  155.  
  156. void AMIGA_Window::drawLine(int x1, int y1, int x2, int y2)
  157.  
  158.   Move(rp,x1,w_yres-y1);
  159.   Draw(rp,x2,w_yres-y2);
  160.  
  161. }
  162.  
  163.  
  164. void AMIGA_Window::flush()
  165. {
  166.  
  167.   printf("Window flush\n");
  168.  
  169.   BaseWindow::flush();
  170.  
  171. }
  172.  
  173.